
const L = [0, 'a', 'b', 'c', 'd', 'e', 'f',
  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
  'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  'w', 'x', 'y', 'z']

function findKthBit(n, k) {
  const dp = [0, 'a'];
  for (let i = 2; i <= n; i++) {
    let str = invert(dp[i - 1]);
    dp[i] = dp[i - 1] + L[i] + reverse(str);
  }

  function invert(str) {
    let s = '';
    for (let i = 0; i < str.length; i++) {
      for (let j = 1; j < L.length; j++) {
        if (str[i] === L[j]) {
          s = s + L[L.length - j];
          break;
        }
      }
    }
    return s;
  }

  function reverse(str) {
    let s = '';
    for (let i = str.length - 1; i >= 0; i--) {
      s = s + str[i]
    }
    return s
  }
  return dp[n][k - 1];
}

console.log(findKthBit(4, 11));